﻿using System.Collections.Generic;
using System.IO;
using UnityEditor;
using UnityEngine;

public class EditorTools : MonoBehaviour
{
    [MenuItem("工具/打开沙盒文件夹")]
    static void OpenPersistentDataPath()
    {
        System.Diagnostics.Process.Start(@Application.persistentDataPath);
    }

    [MenuItem("工具/清除登录信息")]
    static void ClearPlayerPrefs()
    {
        PlayerPrefs.DeleteAll();
    }

    [MenuItem("工具/创建版本文件")]
    static void CreatVersionFile()
    {
        ResVersion resVersion = new ResVersion();
        resVersion.resFiles = new List<ResFile>();
        DirectoryInfo folder = new DirectoryInfo(Application.streamingAssetsPath);

        foreach (FileInfo file in folder.GetFiles())
        {
            if (file.Name.Contains(".DS_Store") || file.Name.Contains(".meta") || file.Name.Contains(".txt"))
            {
                continue;
            }
            file.MoveTo(file.FullName.ToLower() + ".t");

            ResFile rf = new ResFile();
            rf.name = Path.GetFileName(file.FullName);
            rf.md5 = Util.GetFileMD5(file.FullName);
            resVersion.resFiles.Add(rf);
        }
        string jsonString = JsonUtility.ToJson(resVersion);
        File.WriteAllText(Application.streamingAssetsPath + "/version.txt", jsonString);
        AssetDatabase.Refresh();
    }
}